/*
 * @Description: 
 * @Version: 1.0
 * @Autor: ziwei
 * @Date: 2021-06-29 14:17:35
 * @LastEditors: ziwei
 * @LastEditTime: 2021-06-29 15:39:02
 */
//关键是前缀 所以用startWith
strs = ["dog","racecar","car"];

var longestCommonPrefix = function(strs) {
  let str = strs[0];
  for(let i=0;i<strs.length;i++){
     while(!strs[i].startsWith(str)){
         if(str.length==0){return str=""}
         str = str.substring(0,str.length-1)
     }     
  }
  return str;
};

longestCommonPrefix(strs);